package sdk.org.apache.shiro.G2_使用.C07_1Web集成_登录和退出.services;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.titan.core.apidoc.annotations.ApiAuthor;
import com.titan.core.apidoc.annotations.ApiDescription;
import com.titan.core.apidoc.annotations.ApiEmail;
import com.titan.core.apidoc.annotations.ApiVersion;
import com.titan.core.base.BaseHtmlV8;
import com.titan.services.GenerateCode.v8.ViewXML.tags.html.HtmlTagV8;
import com.titan.services.GenerateCode.v8.ViewXML.tpl.options.PageOption;
import com.titan.services.GenerateCode.v8.common.utils.JsBuilderV8;

import sdk.org.apache.shiro.utils.ShiroUtils;

/**
 * This software is Copyright ©2018 ChengGong studio. All Rights Reserved.
 * The source code contained in this listing is proprietary to 周成功工作室.
 * Unauthorized copying, adaptation, distribution, use, or display is strictly prohibited.
 */
@ApiDescription("用户身份认证页面")
@ApiAuthor("周成功")
@ApiEmail("86898837@qq.com")
@ApiVersion("1.0.20190220")
@RestController
@SuppressWarnings("static-access")
public class AuthenticatedController extends BaseHtmlV8 {
    @RequestMapping("/authenticated")
    public void page(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Subject subject = SecurityUtils.getSubject();
        request.getRequestDispatcher("/authenticated/success").forward(request, response);
    }
    
    
    @RequestMapping("/authenticated/success")
    public void success(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String username = ShiroUtils.getUsername(request);
        HtmlTagV8 html = this.tplC8.html(username+"身份验证已通过。");
        
        JsBuilderV8 style = JsBuilderV8.$().addLines(".error{color:red;}");
        JsBuilderV8 script = JsBuilderV8.$().addLines(this.NULL_LINE);
        PageOption spa = this.defaultContext(request, response);
        String htmlFull = this.page(spa, style, script, html);
        this.writeHtml(response, htmlFull);
    }
}
